import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { HttpExceptionFilter } from './common/filters/http-exception.filter';
import { ApiParamsValidationPipe } from './user/pipes/api-params-validation.pipe';
import { static as resource } from 'express'


async function bootstrap() {
  const app = await NestFactory.create(AppModule)

  // 静态资源
  app.use('/static', resource('resource'))

  // 指定模板引擎
  app.engine('art', 'art')

  // 设置模板引擎配置
  app.set('view options', {
    debug: process.env.NODE_ENV !== 'production',
    minimize: true,
    rules: [
      { test: /<%(#?)((?:==|=#|[=-])?)[ \t]*([\w\W]*?)[ \t]*(-?)%>/ },
      { test: /{%([@#]?)[ \t]*(\/?)([\w\W]*?)[ \t]*%}/ }
    ]
  })

  app.setBaseViewsDir('resource/views')


  app.useGlobalFilters(new HttpExceptionFilter())
  app.useGlobalPipes(new ApiParamsValidationPipe())
  
  await app.listen(3000)
}


bootstrap();
